import BaseModel from './BaseModel'
import { post, get } from '@/api/ajax'
import API from '@/api/apis'
import { DateFormat } from 'yb-tool'

class FeedBack extends BaseModel {

  // 反馈名称
  public name = ''
  // 反馈人的手机号
  public phone = ''
  // QQ
  public qq = ''
  // 微信
  public wx = ''
  // 是否显示在反馈列比饿哦
  public isShow = false
  // 反馈的时间
  public date = ''
  public dateStr = ''
  // 反馈的内容
  public content = ''

  // 构造方法
  constructor() {
    super()
  }

  setDataWithJson(json: object) {
    super.setDataWithJson(json)
    this.dateStr = DateFormat(new Date(this.date))
  }

  // 添加意见反馈
  addFeedBack() {
    return new Promise((resolve, reject) => {
      post(API.feedback.add, this.getJson(['name', 'phone', 'qq', 'wx', 'isShow', 'content'])).then((data) => {
        resolve(data)
      }).catch((err) => {
        reject(err)
      })
    })
  }
  // 更改数据
  update() {
    return new Promise((resolve, reject) => {
      post(API.feedback.update, {
        id: this._id,
        isShow: this.isShow
      }).then((data) => {
        resolve(data)
      }).catch((err) => {
        reject(err)
      })
    })
  }
  // 删除
  removeData() {
    return new Promise((resolve, reject) => {
      get(API.feedback.dustbinPush, {
        id: this._id
      }).then((data) => {
        resolve(data)
      }).catch((err) => {
        reject(err)
      })
    })
  }
}

export default FeedBack
